#include "atlas_kernel.cuh"
#include "cuda_info.hh"

__global__ void atlas_kernel_calcSqrs(SpaceObjectAtlas::SOA_Data *data, unsigned int count){
	int index = threadIdx.x + blockIdx.x * blockDim.x;
	if(index < count){
		data[index].sphereRadiusSqr = data[index].sphereRadius * data[index].sphereRadius;
	}
}

void atlas_cuda_calcSqrs(SpaceObjectAtlas::SOA_Data *data, unsigned int count){
	unsigned int blocks = 1;
	unsigned int threads = 1;
	if(count < cuda_info->threadsInBlock){
/*		if(count < cuda_info->warpSize){
			threads = cuda_info->warpSize;
		} else {
			threads = (count - 1) / cuda_info->warpSize + 1;
		}*/
		threads = count;
	} else {
		threads = cuda_info->threadsInBlock;
		blocks = (count - 1) / threads + 1;
	}

	atlas_kernel_calcSqrs<<<blocks,threads>>>(data, count);
}
